#测试登录界面
import time
from selenium.webdriver.common.by import By
from common.Utils import CloudDriver

class Login:
    url=""
    driver=""
    def __init__(self):
        self.url="http://vnollx.cloud/login"
        self.driver=CloudDriver.driver
        self.driver.get(self.url)

    #测试登录成功
    def LoginSuccess(self):
        #查找输入框，为了不出现意外先清空再输入数据
        self.driver.find_element(By.CSS_SELECTOR,"#phone").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#password").clear()

        #输入正确的账号和密码
        self.driver.find_element(By.CSS_SELECTOR, "#phone").send_keys("17384050350")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        #然后点击登录按钮
        self.driver.find_element(By.CSS_SELECTOR,"#form > button").click()
        #判断是否登录成功，可以根据登陆之后的页面元素来判断，没找到会报错,注意页面跳转后查找元素一般需要等待一下，不然还没加载出来是找不到元素的
        # time.sleep(2)
        word=self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.sidebar > div > p").text
        assert word=="普通用户"
        # self.driver.quit()
        #返回
        # self.driver.back()

    def LoginFialed(self):
        # 查找输入框，为了不出现意外先清空再输入数据
        self.driver.find_element(By.CSS_SELECTOR, "#phone").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()

        # (1)输入正确的账号和错误密码(此处只测该用例)
        self.driver.find_element(By.CSS_SELECTOR, "#phone").send_keys("17384050350")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("12345")
        #然后点击登录按钮
        self.driver.find_element(By.CSS_SELECTOR,"#form > button").click()
        time.sleep(2)
        word = self.driver.find_element(By.CSS_SELECTOR, "#swal2-title").text
        assert word == "操作失败"
        self.driver.find_element(By.CSS_SELECTOR, "body > div.swal2-container.swal2-center.swal2-backdrop-show > div > div.swal2-actions > button.swal2-confirm.swal2-styled").click()
        # time.sleep(1)
        # self.driver.quit()


#fordebug
# login=Login()
# login.LoginSuccess()
# login.LoginFialed()
